
#include "core/logs.h"
#include "core/threads.h"

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

#define LOG_BUFFER_SIZE 1024

void ve_log( int level, const char *message )
{
	switch( level )
	{
	case VE_LOG_DEBUG:
		printf( "(DD): %s\n", message );
		break;
	case VE_LOG_INFO:
		printf( "(II): %s\n", message );
		break;
	case VE_LOG_WARNING:
		printf( "(WW): %s\n", message );
		break;
	case VE_LOG_ERROR:
		printf( "(EE): %s\n", message );
		break;
	case VE_LOG_FATAL:
		printf( "(FATAL): %s\n", message );
		abort();
		break;
	default:
		printf( message );
	}
}

#define VE_LOG_MACRO(Name,Level) \
	void Name( const char *format, ... ) \
	{ \
		char buf[LOG_BUFFER_SIZE]; \
		va_list args; \
		va_start( args, format ); \
		vsnprintf( buf, LOG_BUFFER_SIZE, format, args ); \
		ve_log( Level, buf ); \
	}

VE_LOG_MACRO( ve_log_debug,   VE_LOG_DEBUG   )
VE_LOG_MACRO( ve_log_info,    VE_LOG_INFO    )
VE_LOG_MACRO( ve_log_warning, VE_LOG_WARNING )
VE_LOG_MACRO( ve_log_error,   VE_LOG_ERROR   )
VE_LOG_MACRO( ve_log_fatal,   VE_LOG_FATAL   )
